<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    $(document).ready(function() {
    	selectCartonCallBack($("#commaCartonId").val());
    });
    //删除方法
    function delEnchase(){
    	if (confirm("确定删除吗？")) {
	        // 调用后台删除方法
	        $.post("${ctx}/customenchase/single/delete?id=${enchase.id}",'',function(result){
	             // 提示信息
	             tipParent(result.message);
	             // 返回状态
	            if(result.statusCode==STATUSCODEOK){
	                 // 刷新页面
	                window.parent.frames[0].searchListForm();
	                 // 关闭页面
	                closeWin(); 
	             }
	        },'json');
		}
   }
    
  //删除方法
    function enchaseCommit(){
    	if (confirm("确定提交吗？")) {
	        // 调用后台删除方法
	        $.post("${ctx}/customenchase/single/commit?id=${enchase.id}",'',function(result){
	             // 提示信息
	             tipParent(result.message);
	             // 返回状态
	            if(result.statusCode==STATUSCODEOK){
	                 // 刷新页面
	                window.parent.frames[0].searchListForm();
	                 // 关闭页面
	                closeWin(); 
	             }
	        },'json');
		}
   }
    
    
 // 选择纸箱回调
    function selectCartonCallBack(commaCartonId){
    	$("#activity_pane").showLoading();
		if(commaCartonId != null && commaCartonId != '' && commaCartonId != "undefined"){
			$("#commaCartonId").val(commaCartonId);
	    	// 格式化，去除逗号
	 	    var params = $("#inputForm").serialize();
	        // 调用后台更新数据
	        $.post("${ctx}/customenchase/single/addCarton",params,function(result) {
	            // 回调函数赋值
	            var h = $(callBackHtml(result)).find("#tableCartonList").html();
	            $('#tableCartonList').html(h);
	            enchaseCloud();
	        }, 'html');
		}
    }
    function enchaseCloud() {
    	var id = $("#id").val();
		var targetDateStr = $("#targetDate").val();
		var bigCartonId = $(".hiddenCartonInfoListId")[1].value;
		var smallCartonId = $(".hiddenCartonInfoListId")[0].value;
		var bigCartonWeight = $(".hiddenCartonInfoListCartonWeight")[1].value;
		var smallCartonWeight = $(".hiddenCartonInfoListCartonWeight")[0].value;
		var bigCartonVolume = $(".hiddenCartonInfoListCartonVolume")[1].value;
		var smallCartonVolume = $(".hiddenCartonInfoListCartonVolume")[0].value;
		var bigCartonType = $(".cartonInfoName")[1].value;
		bigCartonType = bigCartonType.split("-")[1];
		var smallCartonType = $(".cartonInfoName")[0].value;
		smallCartonType = smallCartonType.split("-")[1];
		$.post("${ctx}/customenchase/single/makeEnchaseListShow?id="+id+"&bigCartonId="+bigCartonId+"&smallCartonId="+smallCartonId+"&bigCartonType="+bigCartonType+"&targetDateStr="+targetDateStr+"&smallCartonType="+smallCartonType+"&bigCartonWeight="+bigCartonWeight+"&smallCartonWeight="+smallCartonWeight+"&bigCartonVolume="+bigCartonVolume+"&smallCartonVolume="+smallCartonVolume,"",function(result){
			// 回调函数赋值
            var h = $(callBackHtml(result)).find("#tablePackageDetailsList").html();
            $('#tablePackageDetailsList').html(h);
            var y = $(callBackHtml(result)).find("#tableIndentList").html();
            $('#tableIndentList').html(y);
            var smallCount = $("#smallCount").val();
            var bigCount = $("#bigCount").val();
            $(".tdCartonInfoListCartonNumber")[0].innerHTML = smallCount;
            $(".tdCartonInfoListCartonNumber")[1].innerHTML = bigCount;
            $("#activity_pane").hideLoading();
        },'html'); 
	}
    
 // 导出
	function exportYYDetail() {
		$("#activity_pane").showLoading();
		$.post('${ctx}/customenchase/single/exportFile?id=${enchase.id}', "", function(result) {
			if (result == "cloud") {
				var targetDate = $("#targetDate").val();
				window.location.href='${ctx}/customenchase/single/makeExportFile?targetDate='+targetDate;
				$("#activity_pane").hideLoading();
			} else {
				alert("导出失败，请重新导出。");
				$("#activity_pane").hideLoading();
			}
		}, 'json');
	}
    </script> 
</head>
<body>   
<div class="layerHeader clearfix">
	<p class="headerTitle"><spring:message code="enchase_show_title"/></p>
    <div class="headerButton clearfix">
    	<!-- 导出 -->
    	<button type="button" onclick="exportYYDetail();">导出</button>
        <c:if test="${enchase.deleteFlag != 1}">
	        <c:if test="${enchase.packageAuditStatus == 'AUDIT_STATUS-AUDIT_00'}">
	        <shiro:hasPermission name="customenchase:single:edit">	
	        	<!-- 提交 -->
    			<button type="button" onclick="enchaseCommit();">提交</button>
		        <!-- 删除 -->
		        <button type="button" id="btnDel" onclick="delEnchase();"><spring:message code="role_delete"/></button>
		        <!-- 编辑 -->
		        <button type="button" id="btnEdit" onClick="window.location.href='${ctx}/customenchase/single/form?id=${enchase.id}&commaCartonId=${enchase.commaCartonId }'"><spring:message code="write_style_btn"/></button>
        	</shiro:hasPermission>
        	</c:if>
        	<c:if test="${enchase.packageAuditStatus != 'AUDIT_STATUS-AUDIT_00'}">
	        <shiro:hasPermission name="customenchase:single:audit">
	        		<button type="button" onclick="popup('800px','519px','${ctx}/customenchase/single/audit?id=${enchase.id}')">审核</button>
        	</shiro:hasPermission>
        	</c:if>
        </c:if>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
    </div>
</div>
<input type="hidden" id="targetDate" value="<fmt:formatDate value="${enchase.targetDate}" pattern="yyyy-MM-dd"/>"/>
<form id="inputForm" method="post" >
<input type="hidden" id="commaCartonId" name="commaCartonId" value="${enchase.commaCartonId}"/>
<input type="hidden" id="id" name="id" value="${enchase.id}"/>
<div class="tabBoxSm" id="activity_pane">
 <div class="tabSm" style="padding: 10px 5px;">
  <div style="height:180px;">
    <!-- 合同信息 -->
    <div class="left col-50">
         <p style="margin-top:0;margin-bottom:5px;margin-left:20px;"><span style="font-size:16px;">合同信息</span></p>
         <div class="tableArea">
        	<div class="tableScroll tableScrollSm" style="width:470px;height:142px;">
        		<table cellpadding="0" class="tableHead">
                    <thead>
                    <tr>	
                        <!-- No. -->	
                    	<th style="width:40px;"><spring:message code="enchase_show_styleInfo_no"/></th>
                    	<!-- 合同单号 -->
                        <th><p style="width:250px;"><spring:message code="enchase_show_styleInfo_customerContractNo"/></p></th>
                        <!-- 总件数 -->
                        <th style="width:160px;"><spring:message code="enchase_show_styleInfo_allQuantity"/></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" id="tableIndentList">
                <c:if test="${not empty enchase.contracts}">
                    <tbody>
                    <c:forEach items="${enchase.contracts}" var="contract" varStatus="status">
                    <tr>
                        <!-- NO -->
                    	<td style="width:40px;">${status.count}</td>
                    	<!-- 合同单号 -->
                        <td><p style="width:250px;" class="text_overflow" data-toggle='tooltip' title='${contract.contractNo}'>${contract.contractNo}</p></td>
                        <input type="hidden" name="indentList[${status.index}].customerContractNo" value="${contract.contractNo}"/>
                        <!-- 总件数 -->
                        <td style="width:160px;"><fmt:formatNumber value="${contract.contractCount}" pattern="#,##0"/></td>
                        <input  class="hiddenIndentListIndentNumber" type="hidden" name="indentList[${status.index}].indentNumber" value="${contract.contractCount}"/>
                    </tr>
                    </c:forEach>
                    </tbody>
                </c:if>
                </table>
            </div>
        </div>
    </div>
    <!-- 纸箱信息 -->
    <div class="right col-50">
         <p style="margin-top:0;margin-bottom:5px;margin-left:20px;"><span style="font-size:16px;"><spring:message code="enchase_show_cartonInfo_title"/></span></p>
         <div class="tableArea">
        	<div class="tableScroll tableScrollSm" style="width:484px;height:142px;">
        		<table cellpadding="0" class="tableHead">
                    <thead>
                    <tr>
                        <!-- No. -->
                    	<th style="width:30px;"><spring:message code="enchase_show_cartonInfo_no"/></th>
                    	<!-- 箱体名称 -->
                        <th style="width:100px;"><spring:message code="enchase_show_cartonInfo_cartonName"/></th>
                        <!-- 长 -->
                        <th style="width:55px;"><spring:message code="enchase_show_cartonInfo_length"/></th>
                        <!-- 宽 -->
                        <th style="width:55px;"><spring:message code="enchase_show_cartonInfo_width"/></th>
                        <!-- 高 -->
                        <th style="width:55px;"><spring:message code="enchase_show_cartonInfo_height"/></th>
                        <!-- 体积 -->
                        <th style="width:55px;"><spring:message code="enchase_show_cartonInfo_volume"/></th>
                        <!-- 箱重 -->
                        <th style="width:55px;"><spring:message code="enchase_show_cartonInfo_weight"/></th>
                        <!-- 总数 -->
                        <th style="width:60px;"><spring:message code="enchase_show_cartonInfo_allQuantity"/></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" id="tableCartonList">
                <c:if test="${not empty enchase.cartonInfoList}">
                    <tbody>
                    <c:forEach items="${enchase.cartonInfoList}" var="cartonInfo" varStatus="status">
                    	<tr>
                    	    <!-- NO -->
							<td style="width:30px;">${status.index+1}</td>
							<!-- 箱体名称 -->
							<td style="width:100px;">${cartonInfo.cartonName}</td>
							<input class="cartonInfoName" type="hidden" name="cartonInfoList[${status.index}].cartonName" value="${cartonInfo.cartonName}"/>
							<!-- 长 -->
							<td style="width:55px;"><fmt:formatNumber value="${cartonInfo.cartonLength}" pattern="#,##0.####"/></td>
							<input type="hidden" name="cartonInfoList[${status.index}].cartonLength" value="${cartonInfo.cartonLength}"/>
							<!-- 宽 -->
							<td style="width:55px;"><fmt:formatNumber value="${cartonInfo.cartonWidth}" pattern="#,##0.####"/></td>
							<input type="hidden" name="cartonInfoList[${status.index}].cartonWidth" value="${cartonInfo.cartonWidth}"/>
							<!-- 高 -->
							<td style="width:55px;"><fmt:formatNumber value="${cartonInfo.cartonHeight}" pattern="#,##0.####"/></td>
							<input type="hidden" name="cartonInfoList[${status.index}].cartonHeight" value="${cartonInfo.cartonHeight}"/>
							<!-- 体积 -->
							<td style="width:55px;"><fmt:formatNumber value="${cartonInfo.cartonVolume}" pattern="#,##0.####"/></td>
							<input class="hiddenCartonInfoListCartonVolume" type="hidden" name="cartonInfoList[${status.index}].cartonVolume" value="${cartonInfo.cartonVolume}"/>
							<!-- 箱重 -->
							<td style="width:55px;"><fmt:formatNumber value="${cartonInfo.cartonWeight}" pattern="#,##0.####"/></td>
							<input class="hiddenCartonInfoListCartonWeight" type="hidden" name="cartonInfoList[${status.index}].cartonWeight" value="${cartonInfo.cartonWeight}"/>
							<!-- 总数 -->
							<td class="tdCartonInfoListCartonNumber" style="width:60px;"><fmt:formatNumber value="${cartonInfo.cartonNumber}" pattern="#,##0"/></td>
							<input class="hiddenCartonInfoListCartonNumber" type="hidden" name="cartonInfoList[${status.index}].cartonNumber" value="${cartonInfo.cartonNumber}"/>
							<!-- id -->
							<td class="none">${cartonInfo.id}</td>
							<input class="hiddenCartonInfoListId" type="hidden" name="cartonInfoList[${status.index}].id" value="${cartonInfo.id}"/>
						</tr>
					</c:forEach>	
                    </tbody>
                </c:if>    
                </table>
            </div>
        </div>
    </div>
  </div>
  <div>
      <div class="items clearfix" id="pagePackageStyleValue">
	      <p style="margin-top:0;margin-bottom:0px;margin-left:10px;"><span style="font-size:16px;"><spring:message code="enchase_show_package_title"/></span>
	      <!-- 总件数 -->
	      <span style="color:#d6392d;right:650px;position:absolute;"><spring:message code="enchase_show_package_allStyleQuantity"/><span class="pagePackageStyleQuantity"><fmt:formatNumber value="${enchase.contractCount}" pattern="#,##0"/></span></span>
	      <!-- 总箱数 -->
	      <span style="color:#d6392d;right:500px;position:absolute;"><spring:message code="enchase_show_package_allCartonQuantity"/><span class="pagePackageQuantity"><fmt:formatNumber value="${enchase.bigCount+enchase.smallCount}" pattern="#,##0"/></span></span>
	      <!-- 总毛重 -->
	      <span style="color:#d6392d;right:350px;position:absolute;"><spring:message code="enchase_show_package_allRoughtWeight"/><span class="pagePackageRoughWeight"><fmt:formatNumber value="${enchase.grossWeight}" pattern="#,##0.000#"/></span></span>
	      <!-- 总净重 -->
	      <span style="color:#d6392d;right:200px;position:absolute;"><spring:message code="enchase_show_package_allNetWeight"/><span class="pagePackageNetWeight"><fmt:formatNumber value="${enchase.netWeight}" pattern="#,##0.000#"/></span></span>
	      <!-- 总体积 -->
	      <span style="color:#d6392d;right:50px;position:absolute;"><spring:message code="enchase_show_package_allVolume"/><span class="pagePackageVolume"><fmt:formatNumber value="${enchase.volume}" pattern="#,##0.000#"/></span></span>
	      <input type="hidden" id="bigCount" name="bigCount" value="${enchase.bigCount}"/>
	      <input type="hidden" id="smallCount" name="smallCount" value="${enchase.smallCount}"/>
	      <input type="hidden" id="contractCount" name="contractCount" value="${enchase.contractCount}"/>
	      </p>
      </div>
      <div class="tableArea">
     	<div class="tableScroll tableScrollSm" style="width:983px;height:420px;">
     		<table cellpadding="0" class="tableHead">
                 <thead>
                 <tr>
                 	 <!-- 大箱号 -->
                     <th><p style="width:100px;">大箱号</p></th>
                     <!-- 小箱号 -->
                     <th><p style="width:115px;">小箱号</p></th>
                     <!-- 订单号 -->
                     <th><p style="width:140px;">订单号</p></th>
                     <!-- 目的地 -->
                     <th><p style="width:100px;">目的地</p></th>
                     <!-- 国家 -->
                     <th><p style="width:100px;">国家</p></th>
                     <!-- Transit group -->
                     <th><p style="width:100px;">Transit group</p></th>
                     <!-- 店铺 -->
                     <th><p style="width:100px;">店铺</p></th>
                     <!-- 成分 -->
                     <th><p style="width:100px;">成分</p></th>
                     <!-- 重要 -->
                     <th><p style="width:50px;">重要</p></th>
                     <!-- 袖子 -->
                     <th><p style="width:50px;">袖子</p></th>
                 </tr>
                 </thead>
             </table>
             <table cellpadding="0" id="tablePackageDetailsList">
                <c:if test="${not empty enchase.enchases}">
                    <tbody>
                    <c:forEach items="${enchase.enchases}" var="bigEnchase" varStatus="bigStatus">
                    <c:forEach items="${bigEnchase.enchases}" var="smallEnchase" varStatus="smallStatus">
                    <c:forEach items="${smallEnchase.enchaseList}" var="enchase" varStatus="status">
                    <tr>
                     <!-- 大箱号 -->
                     <c:if test="${smallStatus.index == 0 && status.index == 0 }">
                     	<td rowspan="${bigEnchase.rowSpan }"><p style="width:100px;" class="text_overflow" title="${bigEnchase.bigCartonNo }" data-toggle="tooltip">${bigEnchase.bigCartonNo }</p></td>
                     </c:if>
                     <!-- 小箱号 -->
                     <c:if test="${status.index == 0 }">
                     	<td rowspan="${fn:length(smallEnchase.enchaseList)}"><p style="width:115px;" class="text_overflow" title="${smallEnchase.smallCartonNo }" data-toggle="tooltip">${smallEnchase.smallCartonNo }</p></td>
                     </c:if>
                     <!-- 订单号 -->
                     <td><p style="width:140px;" class="text_overflow" title="${enchase.orderNO }" data-toggle="tooltip">${enchase.orderNO }</p></td>
                     <!-- 目的地 -->
                     <td><p style="width:100px;" class="text_overflow" title="${enchase.shippingDestintion }" data-toggle="tooltip">${enchase.shippingDestintion }</p></td>
                     <!-- 国家 -->
                     <td><p style="width:100px;" class="text_overflow" title="${enchase.countryName }" data-toggle="tooltip">${enchase.countryName }</p></td>
                     <!-- Transit group -->
                     <td><p style="width:100px;" class="text_overflow" title="${enchase.transitGroup }" data-toggle="tooltip">${enchase.transitGroup }</p></td>
                     <!-- 店铺 -->
                     <td><p style="width:100px;" class="text_overflow" title="${enchase.shopName }" data-toggle="tooltip">${enchase.shopName }</p></td>
                     <!-- 成分 -->
                     <td><p style="width:100px;" class="text_overflow" title="${enchase.materialComposition }" data-toggle="tooltip">${enchase.materialComposition }</p></td>
                     <!-- 重要 -->
                     <td><p style="width:50px;<c:if test="${enchase.urgentCD == 'ORDER_FLAG-express_20' }">color: red;</c:if>">${fns:getDictName(enchase.urgentCD) }</p></td>
                     <!-- 袖子 -->
                     <td><p style="width:50px;"><c:if test="${enchase.sleeveFlag == 0 }">长袖</c:if><c:if test="${enchase.sleeveFlag == 1 }"><p style="color: red;">短袖</p></c:if></p></td>
                    </tr>
                    </c:forEach>
                    </c:forEach>
                    </c:forEach>
                    </tbody>
                </c:if>   
             </table>
         </div>
      </div>
  </div>
 </div>
</div>
</form>
</body>
</html>